package com.bmft.list_view10;


import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.solver.state.helpers.AlignVerticallyReference;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.bmft.MainActivity;
import com.bmft.R;

/**
 * 如果只是继承 Activity 是不是可没有 上边框.
 * 是的，是的，直接继承Activity可以没有上边框 舒服舒服.
 */
public class ListViewActivity10 extends Activity {

    private ListView lv_1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_view10);
        lv_1 = findViewById(R.id.lv_1);
        //这里定义Adapter，实现
        lv_1.setAdapter(new MyListAdapter(ListViewActivity10.this,10));
        //设计点击事件.
        lv_1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(ListViewActivity10.this, "点击 pos: " + position, Toast.LENGTH_SHORT).show();
            }
        });
        //设计长按事件.
        //true if the callback consumed the long click, false otherwise.
        //true就是不会再次触发点击事件
        lv_1.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                Toast.makeText(ListViewActivity10.this, "长按 pos: " + v.getId(), Toast.LENGTH_SHORT).show();
                return true;
            }
        });
    }

    public void backToMain(View view) {
        Intent intent = new Intent(ListViewActivity10.this, MainActivity.class);
        startActivity(intent);
    }
}